using System;
using ConsentManagementProviderLib.EventHandlerInterface;
using ConsentManagementProviderLib.Observer;
using UnityEngine;
using UnityEngine.EventSystems;

namespace ConsentManagementProviderLib
{
	public static class ConsentMessenger
	{
		public static void AddListener<T>(GameObject go) where T : IConsentEventHandler
		{
			BroadcastReceivers.RegisterBroadcastReceiver<T>(go);
		}

		public static void RemoveListener<T>(GameObject go) where T : IConsentEventHandler
		{
			BroadcastReceivers.UnregisterBroadcastReceiver<T>(go);
		}

		public static void Broadcast<T>(params object[] list) where T : IConsentEventHandler
		{
			CmpDebugUtil.LogWarning("T == " + typeof(T).Name);
			switch (typeof(T).Name)
			{
			case "IOnConsentReady":
			{
				SpConsents consents = (SpConsents)list[0];
				BroadcastEventDispatcher.Execute(null, delegate(IOnConsentReady i, BaseEventData d)
				{
					i.OnConsentReady(consents);
				});
				break;
			}
			case "IOnConsentAction":
			{
				CONSENT_ACTION_TYPE actionType = (CONSENT_ACTION_TYPE)list[0];
				BroadcastEventDispatcher.Execute(null, delegate(IOnConsentAction i, BaseEventData d)
				{
					i.OnConsentAction(actionType);
				});
				break;
			}
			case "IOnConsentError":
			{
				Exception exception = (Exception)list[0];
				BroadcastEventDispatcher.Execute(null, delegate(IOnConsentError i, BaseEventData d)
				{
					i.OnConsentError(exception);
				});
				break;
			}
			case "IOnConsentUIReady":
				BroadcastEventDispatcher.Execute(null, delegate(IOnConsentUIReady i, BaseEventData d)
				{
					i.OnConsentUIReady();
				});
				break;
			case "IOnConsentUIFinished":
				BroadcastEventDispatcher.Execute(null, delegate(IOnConsentUIFinished i, BaseEventData d)
				{
					i.OnConsentUIFinished();
				});
				break;
			case "IOnConsentSpFinished":
			{
				SpConsents spConsents = (SpConsents)list[0];
				BroadcastEventDispatcher.Execute(null, delegate(IOnConsentSpFinished i, BaseEventData d)
				{
					i.OnConsentSpFinished(spConsents);
				});
				break;
			}
			}
		}
	}
}
